#!/usr/bin/Python
# encoding: UTF-8
# Created by zhao at 2017/11/22

import pymysql

class TutorialPipeline2mysql(object):
    def process_item(self,item,spider):
        stock_name=item['stock_name'].encode('utf8')
        stock_code=item['stock_code'].encode('utf8')
        stock_dwjz=item['stock_dwjz'].encode('utf8')
        stock_date=item['stock_date'].encode('utf8')

        db=pymysql.connect('127.0.0.1','root','123456','scrapyDB')

        cur=db.cursor()

        cur.execute('insert into FUNDHQ(FDATE,STOCK_CODE,STOCK_NAME,STOCK_DWJZ) values (%s,%s,%s,%s)',
                    (stock_date,stock_code,stock_name,stock_dwjz))

        cur.close()
        db.commit()
        db.close()

        return item